package com.tms;

import com.aliyun.oss.ClientConfiguration;
import com.aliyun.oss.OSSClient;
import com.aliyun.oss.common.auth.DefaultCredentialProvider;
import com.aliyun.oss.model.*;

import java.util.List;

/**
 * 阿里云OSS工具
 */
public class OssBootUtil {

    public static void main(String[] args) {

        /*String bucketName1 = "haoyoukuai";
        OSSClient ossClient1 = new OSSClient("oss-cn-shenzhen.aliyuncs.com",
                new DefaultCredentialProvider("LTAI4GGQhP2TcckQCd4voH9E", "pbqtEF4xgGObvdGxk10cAq4gi8dPml"),
                new ClientConfiguration());*/
        String bucketName2 = "tmsluguang";
        OSSClient ossClient2 = new OSSClient("oss-cn-hangzhou.aliyuncs.com",
                new DefaultCredentialProvider("LTAI5tGdVJJ9UGB86rfZV4Bs", "ybaCwLX4wFRzI0HKT3urU6tsN7e7wl"),
                new ClientConfiguration());

        OSSObject obj = ossClient2.getObject(bucketName2,"upload");
        System.out.println(obj.getKey());
        //ObjectListing objectListing = ossClient2.listObjects(bucketName2);
        ObjectListing objectListing = ossClient2.listObjects(bucketName2,"upload/");

        List<OSSObjectSummary> sums = objectListing.getObjectSummaries();
        for (OSSObjectSummary s : sums) {
            System.out.println(s.getType());
            System.out.println("\t" + s.getKey());

        }

        /*List<LiveChannel> channels = ossClient2.listLiveChannels(bucketName2);
        System.out.println(channels.size());
        for (LiveChannel c : channels) {
            System.out.println(c.getName());

        }*/

        /*OSSObject ossObject = ossClient1.getObject(bucketName1,"upload/test/e69ac28648a0453e80668c657a5fc4da.jpg");
        System.out.println(ossObject.getKey());*/
        //ossClient2.putObject(bucketName2,ossObject.getKey(),ossObject.getObjectContent());
        //ossClient2.setBucketAcl(bucketName2, CannedAccessControlList.PublicReadWrite);
        //ossClient2.setObjectAcl(bucketName2,ossObject.getKey(), CannedAccessControlList.PublicReadWrite);
    }

}
